<?php
#测试品牌等级升级
ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';
ini_set('memory_limit', '1024M');

$brandId = $argv[1] ?? 0;

if (!$brandId) {
    exitEcho('brand_id required', 1);
}

$level = $argv[2] ?? 0;

$levelGrowthValues = \Biz\pockets\constInterface\BrandLevel::BRAND_LV_GROWTH_VALUE_RANGE[$level] ?? [];

if (empty($levelGrowthValues)) {
    exitEcho('level error!', 2);
}

[$startGrowthValue, $endGrowthValue] = $levelGrowthValues;

$brandInfo = \Biz\model\brand\Brand::getBrandInfoById($brandId);

if (empty($brandInfo)) {
    exitEcho('brand not found!', 3);
}

if ($brandInfo['level'] == $level) {
    exitEcho('品牌已经是该等级了');
}

\Biz\model\brand\Brand::updateBrandInfoById($brandId, ['level' => $level, 'growth_value' => $startGrowthValue + 10]);

$bRet = \Biz\service\BrandRights\BrandLevelRightsService::upgradeLevelRights($brandId, $level);

if (!$bRet) {
    exitEcho('等级权益升级失败！',4);
}

exitEcho('等级权益升级成功！');

function exitEcho(string $msg, int $exitCode = 0)
{
    echo $msg . PHP_EOL;
    exit;
}

